//
//  LEStaffDetialController.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/10.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LEStaffDetialController.h"
#import "LEStaffDetailNameCell.h"
#import "LEStaffDeatilAddressCell.h"
#import "LEStaffDetialIdentifyCardCell.h"
#import "LEStaffDetialModel.h"

#import "LEImageBrowerController.h"

static NSString *const LEStaffDetailNameCellId = @"LEStaffDetailNameCell";
static NSString *const LEStaffDeatilAddressCellId = @"LEStaffDeatilAddressCell";
static NSString *const LEStaffDetialIdentifyCardCellId = @"LEStaffDetialIdentifyCardCell";

@interface LEStaffDetialController ()
/**
 <#Description#>
 */
@property(nonatomic,copy)LEStaffDetialModel *model;
@end

@implementation LEStaffDetialController

- (void)setupUI
{
    [super setupUI];
    self.title = @"员工详情";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"LEStaffDetailNameCell" bundle:nil] forCellReuseIdentifier:LEStaffDetailNameCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEStaffDeatilAddressCell" bundle:nil] forCellReuseIdentifier:LEStaffDeatilAddressCellId];
    [self.tableView registerNib:[UINib nibWithNibName:@"LEStaffDetialIdentifyCardCell" bundle:nil] forCellReuseIdentifier:LEStaffDetialIdentifyCardCellId];
    self.tableView.estimatedRowHeight = 120;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}
- (void)loadData
{
    [self requestRefreshData];
}
#pragma mark- 网络请求
- (void)requestRefreshData
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.service_id forKey:@"service_id"];
    [dict setObject:self.store_id forKey:@"store_id"];
    
    [SVProgressHUD showWithStatus:@"正在加载中"];
    __weak typeof (self) weakSelf = self;
    [API requestAppendKey:StaffDetailUrl params:dict success:^(NSDictionary *successCode) {
        [SVProgressHUD dismiss];
        LELog(@"%s---%d---%@",__func__,__LINE__,successCode);
        NSDictionary *datas = successCode[@"datas"];
        NSString *error = datas[@"error"];
        if (error)
        {
            [SVProgressHUD showErrorWithStatus:error];
        }else
        {
            NSDictionary *serviceInfo = datas[@"service_info"];
            LEStaffDetialModel *detailModel = [LEStaffDetialModel mj_objectWithKeyValues:serviceInfo];
            
            [weakSelf.dataSource addObject:detailModel];
            [weakSelf.tableView reloadData];
        }
        
    } falure:^(NSError *er) {
        LELog(@"%s---%d---%@",__func__,__LINE__,er);
        [SVProgressHUD dismiss];
    }];
}
#pragma mark- tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        LEStaffDetailNameCell *cell = [tableView dequeueReusableCellWithIdentifier:LEStaffDetailNameCellId forIndexPath:indexPath];
        if (self.dataSource.count>0) {
           cell.model = self.dataSource[0];
        }
        return cell;
    }else if (indexPath.row == 1){
        LEStaffDeatilAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:LEStaffDeatilAddressCellId forIndexPath:indexPath];
        if (self.dataSource.count>0) {
            cell.model = self.dataSource[0];
        }
        return cell;
    }else{
        LEStaffDetialIdentifyCardCell *cell = [tableView dequeueReusableCellWithIdentifier:LEStaffDetialIdentifyCardCellId forIndexPath:indexPath];
        if (self.dataSource.count>0) {
            cell.model = self.dataSource[0];
        }
         __weak typeof (self) weakSelf = self;
        [cell identifyCardCellClick:^(UIImage *icon) {
            LEImageBrowerController *imageBrower = [[LEImageBrowerController alloc]init];
            imageBrower.bigImage = icon;
            [weakSelf.navigationController pushViewController:imageBrower animated:YES];
        }];
        return cell;
    }

}

@end











